﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="iBooks._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> 
    <link rel="stylesheet" href="images/builder.css" type="text/css" />
    <title>Parse URL</title>
    <script type="text/javascript">   
	Array.prototype.last = function() {return this[this.length-1];}
	var backActions = [];
    $(document).ready(function(){
		initAction();
    });	
    function initAction()
    {
        $('p').each(function(index){
			$(this).attr('id', 'id' + index);
			if($(this).text().trim() != '' || $(this).html().indexOf('<img')>0)
			{
			    var html = $(this).html();
			    html = html + '<span class="addElement hide">'+
							    '<span class="download-label bt1">download</span>'+
							    '<span class="download-label bt2">download2</span>'+ 
							    '</span>';
			    $(this).html(html);
			}
			else
			{
			    $(this).addClass('hide');
			}
		});
		$('p').mouseover(function(){
			$(this).addClass("row_active");
			$(this).find('.addElement').addClass('show');
			$(this).find('.addElement').removeClass('hide');
		});
		$('p').mouseout(function(){
			$(this).removeClass("row_active");
			$(this).find('.addElement').addClass('hide');
			$(this).find('.addElement').removeClass('show');
		});
        $('.bt1').click(function() {			
			$(this).parent().parent().slideUp('slow',function(){});
			backActions.push({
				'id': $(this).parent().parent().attr('id'),
				'action': 'addClass',
				'value': 'show'
			});
            //$(this).parent().addClass("hide");
        });   
    }
	function undo()
	{
		var action = backActions.pop();
		if(action != null)
		{
			if(action.action == 'addClass')
			{
				$('#'+action.id).slideDown('slow',function(){});
			}
		}
	}
	function parseURL()
	{
	    var url = $('#txtUrl').val();
	    var link="./Ajax/parseURL.aspx?url=" + escape(url);       
	    if($('#cbIsImage').is(":checked"))
	    {
            link = link + "&isImage=1&mWidth=320";	    
	    }
        
        $.ajax({
           type: "get",
           url: link,
           success: function(msg){                
               $('#output').html(msg);
               initAction();               
           }
       });

    }
    function update()
    {
        var book = {};     
        book.name = $('#txtTitle').val();
        book.description = 'Auto created by ibooks.com';
        book.content = $('#output').html();
                                                   
        //photoList.Title = 'list';// $("#lblTitle").text();    
        $.post("AjaxJSONUpdateInfo.aspx", "data="+$.toJSON(book), function(response){ 
                         
        });
    }
    </script> 
</head>
<body>
    <form id="form1" runat="server">
    <div>
         <div style="width:500px;margin-left:auto;margin-right:auto">
             URL<input id="txtUrl" type="text" style="width: 434px" />
             Title<input id="txtTitle" type="text" style="width: 334px" />
             <input id="cbIsImage" type="checkbox" checked="checked" /> Là ảnh
             <input id="btParse" type="button" onclick="parseURL()" value="Parse" />
         </div>
         <div id="output" style="width:500px;margin-left:auto;margin-right:auto">
         
         </div>
    </div>
    </form>
</body>
</html>
